<!-- Teacher_ToDoMessage.html -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>待办事宜消息列表</title>
		<link rel="stylesheet" href="../../css/weui.min.css" />
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<link rel="stylesheet" href="../../css/base.css">
		<style type="text/css">
			.mui-table-view .mui-media-object.mui-pull-left {
				width: 26px;
				height: 26px;
				border-radius: 3px;
			}
			.mui-table-view-cell > a:not(.mui-btn) {
				padding: 10px;
			}
			.message_content {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: pre-line;
				display: -webkit-box;
				-webkit-line-clamp: 1;
				-webkit-box-orient: vertical;
				word-wrap: break-word;
			}
			.message_title {
				width: auto;
				max-width: 100%;
			}
			.hide-redpoint {
				display: none;
			}
			.showDiv {
				text-align: center;
				line-height: 30px;
			}
			.top10bottom10 {
				margin-top: 10px;
				margin-bottom: 10px;
			}
			.stylediline {
				height: 10px;
				background-color: #f3f5f7;
			}
			.mui-table-view-cell:active {
				color: #222222
			}
			/*比深灰浅  普通信息 引导词*/
			.base_dark_grey {
				color: #888888;
			}
			.line_height1 {
				line-height: 1
			}
			.font13 {
				font-size: 13px;
			}
			.top_left_div_style {
				margin-right: 24px;
			}
			.top_right_div_style {
				background-color: #E60012;
				width: 20px;
				text-align: center;
				position: absolute;
				top: 10px;
				right: 10px;
				color: #FFFFFF;
				font-size: 10px;
				height: 20px;
				border-radius: 40px;
			}
		</style>
	</head>
	<body class="message">
		<ul id="msg_list_ul" class="mui-table-view ">
			<!--<li class="mui-table-view-cell">
			<div class="mui-slider-right mui-disabled" >
			<a class="mui-btn mui-btn-red" index="1">删除</a>
			</div>
			<div class="mui-slider-handle mui-table">
			<div class="mui-table-cell">
			左滑自动触发删除
			</div>
			</div>
			</li>
			<div class="stylediline"></div>
			<li class="mui-table-view-cell mui-media">
			<div class="mui-slider-right mui-disabled" >
			<a class="mui-btn mui-btn-red">删除</a>
			</div>
			<div class="mui-slider-handle mui-table">
			<img class="mui-media-object mui-pull-left left-img" src="../../image/icon_msg_test.png" >
			<div class="mui-media-body">
			<div class="top_left_div_style">
			<div class="message_title  mui-ellipsis base_dark_grey font13 line_height1" >课课程名课程名课程名课程名程名课程名课程程名课程名课程程名课程名课程</div>
			<span class="message_content base_dark_grey font13" >2017-06-20 12:00:00</span>
			</div>
			<div class="top_right_div_style">+12</div>
			<div class="top10bottom10" >
			<p class="mui-ellipsis base_black_grey base_title_font">
			<span class="message_title">老师评语</span>
			</p>
			<p class='base_dark_grey font13 content_p'>
			<span class="message_content">课程名称</span>
			</p>
			</div>
			</div>
			<div class=" base_dark_grey font13 showDiv">
			立即查看
			</div>
			</div>
			</li>
			<div class="stylediline"></div>
			<li class="mui-table-view-cell mui-media">
			<img class="mui-media-object mui-pull-left left-img" src="../../image/icon_msg_test.png" >
			<div class="mui-media-body">
			<div class="top_left_div_style">
			<h5 class="message_title  mui-ellipsis base_dark_grey font13 line_height1" >课程名课《程名课程名课程名课程名》</h5>
			<span class="message_content base_grey font13" >2017-06-20 12:00:00</span>
			</div>
			<div class="top_right_div_style">+1</div>
			<div class="top10bottom10" >
			<p class="mui-ellipsis base_black_grey base_title_font">
			<span class="message_title">老师评语</span>
			</p>
			<p class='base_dark_grey font13 content_p'>
			<span class="message_content">课程名称</span>
			</p>
			</div>
			</div>
			<div class=" base_dark_grey font13 showDiv">
			立即查看
			</div>
			</li>-->
			<!--<li class="mui-table-view-cell mui-media"  style="position:relative;">
			<div id="redPointMessage" class="redPointMessage"></div>
			<a class="mui-navigate-right" href="javascript:;">
			<img class="mui-media-object mui-pull-left left-img" src="../../image/icon_msg_test.png" >
			<div class="mui-media-body">
			<p class="mui-ellipsis base_dark_grey base_title_font">
			<span class="message_title">测验提示</span>
			<img class="right-red-point" src="../../image/icon_msg_red.png">
			</p>
			<p class='base_grey base_content_font content_p'>
			<span class="message_content">有未批阅的测验</span>
			</p>
			</div>
			</a>
			</li>
			<li class="mui-table-view-cell mui-media">
			<a class="mui-navigate-right" href="javascript:;">
			<img class="mui-media-object mui-pull-left left-img" src="../../image/icon_msg_evaluate.png" >
			<div class="mui-media-body">
			<p class="mui-ellipsis base_dark_grey base_title_font">
			<span class="message_title">评价提醒</span>
			<img class="right-red-point" src="../../image/icon_msg_red.png">
			</p>
			<p class='base_grey base_content_font content_p'>
			<span class="message_content">有未评价的现场实操</span>
			</p>
			</div>
			</a>
			</li>
			<li class="mui-table-view-cell mui-media">
			<a class="mui-navigate-right" href="javascript:;">
			<img class="mui-media-object mui-pull-left left-img" src="../../image/icon_msg_homework.png" >
			<div class="mui-media-body">
			<p class="mui-ellipsis base_dark_grey base_title_font">
			<span class="message_title">作业批阅提醒</span>
			<img class="right-red-point" src="../../image/icon_msg_red.png">
			</p>
			<p class='base_grey base_content_font content_p'>
			<span class="message_content">有为批阅的作业</span>
			</p>
			</div>
			</a>
			</li>-->
		</ul>
		<div id="offlineAlert" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title">是否确定删除？</strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
					<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default">取消</a>
					<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
		<div class="noSign" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无消息
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button" class="mui-btn mui-btn-outlined" onclick="refreshData()">
				重新加载
			</button>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script type="text/javascript" src="../../script/push.js"></script>
	<script type="text/javascript" src="../../script/mui.min.js"></script>
	<script type="text/javascript">
		var page = 1;
		var rows = 10;
		var dropRefreshCount = 0;
		var messageArr = new Array();
		var isFirstLoad = true;
		var li = '';
		var mui = mui.init();
		;
		var indexi = "";
		apiready = function() {
			//
			loadNewData();
			setRefreshHeader();
			setPullUpRefresh();
			$('#msg_list_ul').on('tap', '.mui-btn', function(event) {
				var elem = this;
				indexi = $(this).attr('index');
				//			alert(parseInt(index));
				li = elem.parentNode.parentNode;
				$('#offlineAlert').show();
			})
			sendBuriedNotifi('0', '师傅端消息列表', '248');
		}
		//取消
		function cleanCancel() {
			$('#offlineAlert').hide();
			setTimeout(function() {
				mui.swipeoutClose(li);
			}, 0);
		}

		//确定删除
		function cleanConfirm() {
			//        li.parentNode.removeChild(li);
			var msgData = messageArr[parseInt(indexi)];
			uploadReadStatus(msgData, 3);
			$('#offlineAlert').hide();
		}

		function loadMessageData() {
			var jid = $api.getStorage('cfnetppjxid');
			if (jid == null || jid == undefined || jid == '') {
				jid = 0;
			}
			consoleTest("teacher cid :" + api.pageParam.cid);
			var params = {
				uid : $api.getStorage('cfnetppuid'),
				jid : jid,
				sjid : $api.getStorage('cfnetppjid'), //实习 jid
				page : page,
				rows : rows,
			};
			//      alert("Teacher_ToDoMessage params : " + JSON.stringify(params));
			cfnetppPOST(url_getMasterNoList, params, false, function(data, status) {
				//			 alert("统计分析"+JSON.stringify(data));
				api.refreshHeaderLoadDone();
				api.hideProgress();
				if (status == 'success') {
					if (data.status == true) {
						if (page == 1) {
							messageArr = new Array();
						}
						var msgs = data.data.list;
						if (msgs != undefined && msgs != null && msgs != '' && msgs.constructor == Array && msgs.length > 0) {
							dropRefreshCount = msgs.length;
							// var toDoMsgArr = toDoMsgArrWithArr(msgs);
							var count = messageArr.length;
							messageArr = messageArr.concat(msgs);
							setupMsgDataArr(count, msgs);
							$('#noData').hide();
							$('#noNet').hide();
						} else {
							if (page == 1) {
								$('#msg_list_ul').html('');
								$('#noData').show();
								$('#noNet').hide();
							}
						}
					} else {
						if (page == 1) {
							$('#msg_list_ul').html('');
							$('#noData').show();
							$('#noNet').hide();
						}
					}
				} else {
					if (page > 1) {
						page--;
						dropRefreshCount = rows;
					} else {
						$('#msg_list_ul').html('');
						$('#noData').hide();
						$('#noNet').show();
					}
				}
			});
		}

		function setupMsgDataArr(count, arr) {
			var messageHtmlString = "";
			for (var i = 0; i < arr.length; i++) {
				var msgData = arr[i];
				messageHtmlString += messageHtmlWithData(i + count, msgData);
			}
			if (page == 1) {
				$('#msg_list_ul').html(messageHtmlString);
			} else {
				$('#msg_list_ul').append(messageHtmlString);
			}
			addCellClick();
		}

		function toDoMsgArrWithArr(arr) {
			var todoMsgArr = new Array();
			for (var i = 0; i < arr.length; i++) {
				var courseData = arr[i];
				var courseid = courseData.courseid;
				var coursename = courseData.coursename;
				var planid = courseData.planid;
				var cydata = courseData.cyData;
				if (cydata != undefined && cydata != null && cydata.constructor == Array && cydata.length > 0) {
					for (var j = 0; j < cydata.length; j++) {
						var testData = cydata[j];
						testData["msgType"] = 0;
						//测验
						testData["courseid"] = courseid;
						testData["coursename"] = coursename;
						testData["planid"] = planid;
						var unreadNum = testData.weiyuenumber;
						if (unreadNum != 0) {
							testData["isMessage"] = 0;
						} else {
							testData["isMessage"] = 1;
						}
						todoMsgArr.push(testData);
					}
				}
				var zydata = courseData.zyData;
				if (zydata != undefined && zydata != null && zydata.constructor == Array && zydata.length > 0) {
					for (var j = 0; j < zydata.length; j++) {
						var homeWorkData = zydata[j];
						homeWorkData["msgType"] = 1;
						//作业
						homeWorkData["courseid"] = courseid;
						homeWorkData["coursename"] = coursename;
						homeWorkData["planid"] = planid;
						var unreadNum = homeWorkData.weiyuenumber;
						if (unreadNum != 0) {
							homeWorkData["isMessage"] = 0;
						} else {
							homeWorkData["isMessage"] = 1;
						}
						todoMsgArr.push(homeWorkData);
					}
				}
				var scdata = courseData.scData;
				if (scdata != undefined && scdata != null && scdata.constructor == Array && scdata.length > 0) {
					for (var j = 0; j < scdata.length; j++) {
						var shiCaoData = scdata[j];
						shiCaoData["msgType"] = 2;
						//评价
						shiCaoData["courseid"] = courseid;
						shiCaoData["coursename"] = coursename;
						shiCaoData["planid"] = planid;
						var unreadNum = shiCaoData.weiyuenumber;
						if (unreadNum != 0) {
							shiCaoData["isMessage"] = 0;
						} else {
							shiCaoData["isMessage"] = 1;
						}
						todoMsgArr.push(shiCaoData);
					}
				}
			}
			return todoMsgArr;
		}

		function loadNewData() {
			if (isFirstLoad) {
				isFirstLoad = false;
				api.showProgress({
					style : 'default',
					animationType : 'fade',
					title : '加载中...',
					text : '',
					modal : false
				});
			}
			page = 1;
			loadMessageData();
		}

		function loadMoreData() {
			page++;
			loadMessageData();
		}

		//下拉刷新
		function setRefreshHeader() {
			api.setRefreshHeaderInfo({
				visible : true,
				bgColor : '#ccc',
				textColor : '#fff',
				textDown : '下拉刷新...',
				textUp : '松开刷新...',
				showTime : true
			}, function(ret, err) {
				loadNewData();
			});
		}

		// 上拉加载
		function setPullUpRefresh() {
			api.addEventListener({
				name : 'scrolltobottom'
			}, function(ret, err) {
				if (dropRefreshCount >= rows) {
					dropRefreshCount = 0;
					//防止跳页加载
					loadMoreData();
				}
			});
		}

		function messageHtmlWithData(index, data) {
			var messageTitle = data.cdetailtitle;
			var coursename = data.coursename;
			var msgSubTitle = '';
			var msgSubBotton = '';
			var imgurl = '../../image/icon_msg_test.png';
			//默认为测验10025
			//		if (data.type == 10026) {//作业
			//		     messageTitle = "作业《"+messageTitle+"》&nbsp";
			//			imgurl = "../../image/icon_msg_homework.png";
			//			msgSubTitle= '学生提交了作业,需要审阅';
			//			msgSubBotton = '立即审阅' ;
			//		}else if(data.type == 10027){//现场实操
			//		   messageTitle = "评价《"+messageTitle+"》&nbsp"
			//			imgurl = "../../image/icon_msg_evaluate.png";
			//			msgSubTitle= '学生提交了评价,需要评分';
			//			msgSubBotton = '立即评分' ;
			//		}else if(data.type == 10035){//调查
			//		     messageTitle = "调查《"+messageTitle+"》&nbsp"
			//			imgurl = '../../image/icon_inves_msg.png';
			//			msgSubTitle= '学生提交了调查,需要查看';
			//			msgSubBotton = '立即查看' ;
			//		}else if(data.type == COURSE_CY){//测验
			//		     messageTitle = "测验《"+messageTitle+"》&nbsp"
			//			imgurl = '../../image/icon_msg_test.png';
			//			msgSubTitle= '学生提交了测验,需要批改';
			//			msgSubBotton = '立即批改' ;
			//		}else if(data.type == TEACHER_QD_TYPE){//签到
			//         messageTitle = '签到';
			//			imgurl = "../../image/icon_qiandao_msg.png";
			//			msgSubTitle = data.content;
			//			msgSubBotton = '立即查看' ;
			//
			//			coursename = data.internshipplanname;
			//		}else
			if (data.type == MASTER_NEW_STUDENT) {//徒弟
				messageTitle = '徒弟';
				msgSubTitle = data.content;
				imgurl = "../../image/icon_tudi_msg.png";
				msgSubBotton = '立即审核';
				coursename = data.internshipplanname;
			} else if (data.type == MASTER_DO_SCORE) {//评分
				messageTitle = '评分';
				msgSubTitle = data.content;
				imgurl = "../../image/icon_pinfen_msg.png";
				msgSubBotton = '立即审核';
				coursename = data.internshipplanname;
			} else if (data.type == MASTER_NEW_STUDENT_YB) {//报告
				messageTitle = '报告';
				msgSubTitle = data.content;
				imgurl = '../../image/icon_baogao_msg.png';
				msgSubBotton = '立即审核';
				coursename = data.internshipplanname;
			} else if (data.type == NEW_PX) {//培训
				messageTitle = '培训';
				msgSubTitle = data.content;
				imgurl = '../../image/icon_px_msg.png';
				msgSubBotton = '立即查看';
				coursename = data.internshipplanname;
			} else if (data.type == COURSE_PUBLIC_TYPE) {//公共课程上线了新的课程，也许你会喜欢
				messageTitle = '公共课程';
				imgurl = "../../image/icon_msg_course.png";
				msgSubTitle = data.content;
				coursename = data.internshipplanname;
				msgSubBotton = '立即查看';
			} else if(data.type == MASTER_COURSE_ChAT){
				messageTitle = '课堂圈申请结果';
				imgurl = "../../image/icon_msg_course.png";
				msgSubTitle = data.content;//评语
				coursename = data.internshipplanname;
			}else {
				return '';
			}
			if (messageTitle == undefined || messageTitle == null || messageTitle == '') {
				messageTitle = ' ';
			}
			if (coursename == undefined || coursename == null || coursename == '') {
				coursename = ' ';
			}
			var overtime = data.overtime;
			var timeStr = ' ';
			if (overtime != undefined && overtime != null && overtime != '') {
				timeStr = timeWithStamp3(overtime.toString());
			}
			//		return '<li index="'+index+'" class="msg-cell mui-table-view-cell mui-media" style="position:relative;">'+
			//				'<div id="point'+index+'" class="redPointMessage" style="' + redPointClass+ '"></div>'+
			//				'<a class="mui-navigate-right" href="javascript:;">'+
			//					'<img class="mui-media-object mui-pull-left left-img" src="'+imgurl+'" >'+
			//					'<div class="mui-media-body" style="position:relative;">'+
			//						'<p class="mui-ellipsis base_dark_grey base_title_font">'+
			//							'<span class="message_title">'+messageTitle+'</span>'+
			//						'</p>'+
			//						'<p class="base_grey base_content_font content_p">'+
			//							'<span class="message_content">'+coursename+'</span>'+
			//						'</p>'+
			//					'</div>'+
			//				'</a>'+
			//			'</li>';
			var topRighthtml = '';
			var totalnumber = data.totalnumber;
			// if (parseInt(totalnumber) > 0) {
			// 	topRighthtml = '<div class="top_right_div_style">' + totalnumber + '</div>';
			// }
			return ' <div class="stylediline"></div>' + '<li class="mui-table-view-cell mui-media msg-cell" index="' + index + '" >' + '<div class="mui-slider-right mui-disabled" >' + '<a class="mui-btn mui-btn-red" index="' + index + '" >删除</a>' + '</div>' + '<div class="mui-slider-handle mui-table">' + '<img class="mui-media-object mui-pull-left left-img" src="' + imgurl + '" >' + '<div class="mui-media-body">' + '<div class="top_left_div_style">' + '<div class="message_title  mui-elli1wpsis base_dark_grey font13 line_height1" >' + messageTitle + '</div>' + '<span class="message_content base_dark_grey font13" >' + timeStr + '</span>' + '</div>' + topRighthtml +
			//					'<div class="top_right_div_style">+'+1+'</div>'+
			'<div class="top10bottom10" >' + '<p class=" base_black_grey base_title_font">' + '<span class="">' + msgSubTitle + '</span>' + '</p>' + '<p class="base_dark_grey font13 content_p">' + '<span class="message_content">' + coursename + '</span>' + '</p>' + '</div>' + '</div>' +
					'</div>' + '</li>';
		}

		function addCellClick() {
			$('.msg-cell').unbind('click');
			$('.msg-cell').click(function() {
				var index = $(this).attr('index');
				$('#point' + index).hide();
				//隐藏红点
				var msgData = messageArr[parseInt(index)];
				uploadReadStatus(msgData, 1);
				// pushToNextWin(msgData);
			});
		}

		function pushToNextWin(data) {
			var winName;
			var winPath;
			var pageParam;
			if (data.type == MASTER_DO_SCORE) {//评分
				winName = "Practice_MasterGradeWindow";
				winPath = "Practice_MasterGradeWindow.html";
				pageParam = {
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
				};
			} else if (data.type == MASTER_NEW_STUDENT_YB) {//报告
				winName = "PracticeMasterReportWindow";
				winPath = "PracticeMasterReportWindow.html";
				pageParam = {
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
					index:2
				};
			} else if (data.type == MASTER_NEW_STUDENT) {//徒弟
				winName = "Practice_MasterApprenticeWindow";
				winPath = "Practice_MasterApprenticeWindow.html";
				pageParam = {
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
				};
			} else if (data.type == NEW_PX) {//培训
				winName = "Teacher_TrainSignUp";
				winPath = "../Teacher_Teach/Teacher_TrainSignUp.html";
				pageParam = {
					signUpStatus : 0, //报名状态 0未报名 1 已报名 2已结束
					signUpedUrl : data.visit_url, //跟signUpUrl参数一致 为什么这么传忘了
					lastPageUrl : window.location.pathname, //当前页面的路径 如：“widget://html/Teacher_Teach/Teacher_TrainDetail.html”
					lastPageName : document.title, //当前页面的名称 如“培训详情win”
					signUpUrl : data.visit_url,
					cname : data.internshipplanname //培训名称
				};
			} else if (data.type == COURSE_PUBLIC_TYPE) {//公共课程上线了新的课程，也许你会喜欢
				winName = 'Teacher_StudyCourseInfo', winPath = '../Teacher_Teach/Teacher_StudyCourseInfo.html', pageParam = {
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
					imgurl : data.image,
					title : data.internshipplanname,
					planid : "",
					courseid : data.cid,
					cstatus : "0",
					selected : "1",
					part : "455",
					coursename : data.internshipplanname,
					userType : "student",
					coverimages : data.image,
					isxueba : "0",
					opentype : "courseCenter",
					//hasOwnProperty:"opentype"
				};
			}
			api.openWin({useWKWebView:true,
				name : winName,
				url : winPath,
				pageParam : pageParam
			});
			sendBuriedNotifi('1', '师傅端消息列表', '248');
			loadMessageData();
		}

		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : api.pageParam.accesspagetitle,
				accesspagetitle : api.pageParam.accesspagetitle,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}

		function uploadReadStatus(data, type) {
			var params = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				cid : data.cid,
				vid : data.vid,
				pid : data.pid,
				sjid : $api.getStorage('cfnetppjid'), //实习 jid
				id : data.id,
				stype : type
			};
			//		 alert('url:'+url_toDoMessageSetStatus+'\n'+JSON.stringify(params));
			cfnetppPOST(url_toDoMessageSetStatus, params, false, function(data, status) {
				//		  alert('url:'+url_toDoMessageSetStatus+'\n'+JSON.stringify(data));
				if (data.code == 200) {
					if (type == 3) {
						li.parentNode.removeChild(li);
						api.sendEvent({
							name: 'updateUserNotice',
						});
					}
				}
			});
		}

		function refreshData() {
			isFirstLoad = true;
			loadNewData();
		}
	</script>
</html>